#!/bin/bash
#批量创建用户
#用户名为手动填写的脚本参数,密码随机生成并打印
#创建成功的用户信息追加到文件/root/account_password.system

readonly functions_name="public_functions" #文件名称
readonly functions_url="$(find / -path /proc -prune -o -name $functions_name -print)" #获取文件路径

if [[ -n $functions_url ]]; then #查找函数文件并加载

    for i in $functions_url; do . $i; done
else
    echo "Not fount $functions_name"
fi


user_list=$@

for user in $user_list; do
  if ! id $user &>/dev/null; then
    passwd=$(echo $RANDOM | md5sum | cut -c 1-8)
    useradd $user
    echo $passwd | passwd --stdin $user &>/dev/null
    echo "$user $passwd" >> /root/account_password.system
    logG "user $user create sucessful"
    logG "passwd is $passwd"
  else
    logY "user $user already exists"
  fi
done
